import * as types from '../constants/ActionTypes';

export default function detect(state = [], action = {}) {
    const {
        type, payload
    } = action;
    
    switch (type) {
        case types.DETECT_SUCCESS:
            if (payload.results && payload.results.length) {
                let detectInfo = payload.results[0];
                return {
                    khid : detectInfo.khid,
                    phone : detectInfo.phone,
                    status: 1,
                    message: "用户已注册"
                };
            }else{
                return {
                    status: 0,
                    message: "用户未注册"
                };
            }   
        case types.DETECT_FAILURE:
            return {
                status: -1,
                message: payload.message||'网络连接失败'
            }
        default:
            return state;
    }
}